function printUsage(msg) {
    print("Error: " + msg);
    print("Usage: ./d8_g astd8.js -- <filename.js>");
    quit();
}

if (typeof(arguments) == "undefined") {
    print("No arguments object found - d8 must be used");
    printUsage();
}

var fileName = arguments[0];
if (!fileName) {
    printUsage("Filename required");
}

//var source = "x = 2; if (x > 1) print(x + 3);";
var source;
try { source = read(fileName); } catch (e) { print("Error: File " + fileName + " does not exist"); quit();}

print("--- js source ---");
print(source);
print("");

print("--- ast ---");
var ast = JSON.AST.parse(source);
print(ast);
print("");

/*
print("--- evaluate(ast) ---");
JSON.AST.evaluate(ast);
*/
